package models

import (
	"registration-booking/global"
	"strconv"
	"time"
)

type TestCombo struct {
	ID
	ComboName    string `json:"comboName" gorm:"comment:体检套餐"`
	ComboPicture string `json:"comboPicture" gorm:"comment:套餐图片"`
	Price        string `json:"price" gorm:"comment:价格"`
	Type         string `json:"type" gorm:"comment:类型(0普检、1男性、2 女性)"`
	Tag          string `json:"tag" gorm:"comment:标签"`
	Timestamps
	SoftDeletes
}

func (testCombo TestCombo) GetUid() string {
	return strconv.Itoa(int(testCombo.ID.ID))
}

func FindTestComboById(id uint) (testCombo TestCombo, err error) {
	err = global.App.DB.Where("id = ?", id).First(&testCombo).Error
	return
}

func FindTestComboList() (testCombo []TestCombo, err error) {
	err = global.App.DB.Find(&testCombo).Error
	return
}

func (testCombo *TestCombo) Update() error {
	testCombo.UpdatedAt = time.Now()
	return global.App.DB.Updates(testCombo).Error
}

func (testCombo *TestCombo) Create() error {
	testCombo.CreatedAt = time.Now()
	testCombo.UpdatedAt = time.Now()
	return global.App.DB.Create(testCombo).Error
}

func DeleteTestComboById(id int) error {
	return global.App.DB.Model(TestCombo{}).Delete("id = ?", id).Error
}
